Hệ thống quản lý phòng khám trực tuyến bằng PHP

1 <?php
2     $currDir = dirname(__FILE__);
3     require(
"{$currDir}/incCommon.php");
4     $GLOBALS[
'page_title'] = $Translation['ownership batch transfer'];
5     include(
"{$currDir}/incHeader.php");
6
7     
/* we need the following variables:
8         $sourceGroupID
9         $sourceMemberID (-
1 means "all")
10         $destinationGroupID
11         $destinationMemberID
12
13         
if $sourceGroupID!=$destinationGroupID && $sourceMemberID==-1, an additional var:
14         $moveMembers (=
0 or 1)
15     */

16
17     
// validate input vars
18     $sourceGroupID = intval($_GET[
'sourceGroupID']);
19     $sourceMemberID = makeSafe(strtolower($_GET[
'sourceMemberID']));
20     $destinationGroupID = intval($_GET[
'destinationGroupID']);
21     $destinationMemberID = makeSafe(strtolower($_GET[
'destinationMemberID']));
22     $moveMembers = intval($_GET[
'moveMembers']);
23     $statuses = array();
24
25     
// transfer operations
26     
if($sourceGroupID && $sourceMemberID && $destinationGroupID && ($destinationMemberID || $moveMembers) && isset($_GET['beginTransfer'])){
27         
/* validate everything:
28             
1. Make sure sourceMemberID belongs to sourceGroupID
29             
2. if moveMembers is false, make sure destinationMemberID belongs to destinationGroupID
30         */

31         
if(!sqlValue("select count(1) from membership_users where lcase(memberID)='$sourceMemberID' and groupID='$sourceGroupID'")){
32             
if($sourceMemberID!=-1){
33                 errorMsg($Translation[
'invalid source member']);
34                 include(
"{$currDir}/incFooter.php");
35             }
36         }
37         
if(!$moveMembers){
38             
if(!sqlValue("select count(1) from membership_users where lcase(memberID)='$destinationMemberID' and groupID='$destinationGroupID'")){
39                 errorMsg($Translation[
'invalid destination member']);
40                 include(
"{$currDir}/incFooter.php");
41             }
42         }
43
44         
// get group names
45         $sourceGroup=sqlValue(
"select name from membership_groups where groupID='$sourceGroupID'");
46         $destinationGroup=sqlValue(
"select name from membership_groups where groupID='$destinationGroupID'");
47
48         
// begin transfer
49         
if($moveMembers && $sourceMemberID != -1){
50             $originalValues = array(
'<MEMBERID>', '<SOURCEGROUP>', '<DESTINATIONGROUP>');
51             $replaceValues = array($sourceMemberID, $sourceGroup, $destinationGroup);
52             $statuses[] = str_replace($originalValues, $replaceValues, $Translation[
'moving member']);
53
54             
// change source member group
55             sql(
"update membership_users set groupID='$destinationGroupID' where lcase(memberID)='$sourceMemberID' and groupID='$sourceGroupID'", $eo);
56             $newGroup = sqlValue(
"select name from membership_users u, membership_groups g where u.groupID=g.groupID and lcase(u.memberID)='$sourceMemberID'");
57
58             
// change group of source member's data
59             sql(
"update membership_userrecords set groupID='$destinationGroupID' where lcase(memberID)='$sourceMemberID' and groupID='$sourceGroupID'", $eo);
60             $dataRecs = sqlValue(
"select count(1) from membership_userrecords where lcase(memberID)='$sourceMemberID' and groupID='$destinationGroupID'");
61
62             
// status
63             $originalValues = array(
'<MEMBERID>', '<NEWGROUP>', '<DATARECORDS>');
64             $replaceValues = array($sourceMemberID, $newGroup, $dataRecs);
65             $statuses[] = str_replace($originalValues, $replaceValues, $Translation[
'data records transferred']);
66
67         }elseif(!$moveMembers && $sourceMemberID != -
1){
68             $originalValues = array(
'<SOURCEMEMBER>', '<SOURCEGROUP>', '<DESTINATIONMEMBER>', '<DESTINATIONGROUP>');
69             $replaceValues = array($sourceMemberID, $sourceGroup, $destinationMemberID, $destinationGroup);
70             $statuses[] = str_replace($originalValues, $replaceValues, $Translation[
'moving data']);
71
72             
// change group and owner of source member's data
73             $srcDataRecsBef = sqlValue(
"select count(1) from membership_userrecords where lcase(memberID)='$sourceMemberID' and groupID='$sourceGroupID'");
74             sql(
"update membership_userrecords set groupID='$destinationGroupID', memberID='$destinationMemberID' where lcase(memberID)='$sourceMemberID' and groupID='$sourceGroupID'", $eo);
75             $srcDataRecsAft = sqlValue(
"select count(1) from membership_userrecords where lcase(memberID)='$sourceMemberID' and groupID='$sourceGroupID'");
76
77             
// status
78             $originalValues = array(
'<SOURCEMEMBER>', '<SOURCEGROUP>', '<DATABEFORE>','<TRANSFERSTATUS>', '<DESTINATIONMEMBER>', '<DESTINATIONGROUP>');
79             $transferStatus = ($srcDataRecsAft>
0 ? "No records were transferred" : "These records now belong");
80             $replaceValues = array($sourceMemberID, $sourceGroup, $srcDataRecsBef, $transferStatus ,$destinationMemberID, $destinationGroup);
81             $statuses[] = str_replace ($originalValues, $replaceValues, $Translation[
'member records status']);
82
83         }elseif($moveMembers){
84             $originalValues = array(
'<SOURCEGROUP>', '<DESTINATIONGROUP>');
85             $replaceValues = array( $sourceGroup ,$destinationGroup);
86             $statuses[] = str_replace($originalValues, $replaceValues, $Translation[
'moving all group members']);
87
88             
// change source members group
89             sql(
"update membership_users set groupID='$destinationGroupID' where groupID='$sourceGroupID'", $eo);
90             $srcGroupMembers=sqlValue(
"select count(1) from membership_users where groupID='$sourceGroupID'");
91
92             
// change group of source member's data
93             
if(!$srcGroupMembers){
94                 $dataRecsBef=sqlValue(
"select count(1) from membership_userrecords where groupID='$sourceGroupID'");
95                 sql(
"update membership_userrecords set groupID='$destinationGroupID' where groupID='$sourceGroupID'", $eo);
96                 $dataRecsAft=sqlValue(
"select count(1) from membership_userrecords where groupID='$sourceGroupID'");
97             }
98
99             
// status
100             $originalValues = array(
'<SOURCEGROUP>', '<DESTINATIONGROUP>');
101             $replaceValues = array($sourceGroup ,$destinationGroup);
102             
if($srcGroupMembers){
103                 $statuses[] = str_replace($originalValues, $replaceValues, $Translation[
'failed transferring group members']);
104             }
else{
105                 $statuses[] = str_replace($originalValues, $replaceValues, $Translation[
'group members transferred']);
106
107                 
if($dataRecsAft){
108                     $statuses[] = $Translation[
'failed transfer data records'];
109                 }
else{
110                     $statuses[] = str_replace(
'<DATABEFORE>', $dataRecsBef, $Translation['data records were transferred']);
111                 }
112             }
113
114         }
else{
115             $originalValues = array(
'<SOURCEGROUP>', '<DESTINATIONMEMBER>', '<DESTINATIONGROUP>');
116             $replaceValues = array( $sourceGroup, $destinationMemberID, $destinationGroup);
117             $statuses[] = str_replace ($originalValues, $replaceValues, $Translation[
'moving group data to member']);
118
119             
// change group of source member's data
120             $recsBef = sqlValue(
"select count(1) from membership_userrecords where lcase(memberID)='$destinationMemberID'");
121             sql(
"update membership_userrecords set groupID='$destinationGroupID', memberID='$destinationMemberID' where groupID='$sourceGroupID'", $eo);
122             $recsAft = sqlValue(
"select count(1) from membership_userrecords where lcase(memberID)='$destinationMemberID'");
123
124             
// status
125             $originalValues = array(
'<NUMBER>', '<SOURCEGROUP>', '<DESTINATIONMEMBER>', '<DESTINATIONGROUP>');
126             $recordsNumber = intval($recsAft-$recsBef);
127             $replaceValues = array($recordsNumber, $sourceGroup, $destinationMemberID, $destinationGroup);
128             $statuses[] = str_replace($originalValues, $replaceValues, $Translation[
'moving group data to member status']);
129         }
130
131         
// display status and a batch bookmark for later instant reuse of the wizard
132         $status = implode(
'<br>', $statuses);
133         echo Notification::show(array(
134             
'message' => "<b>{$Translation['status']}</b><br>{$status}",
135             
'class' => 'info',
136             
'dismiss_seconds' => 3600
137         ));
138         ?>
139         <div>
140             <?php
141                 $originalValues = array(
'<SOURCEGROUP>', '<SOURCEMEMBER>', '<DESTINATIONGROUP>', '<DESTINATIONMEMBER>', '<MOVEMEMBERS>');
142                 $replaceValues = array($sourceGroupID, urlencode($sourceMemberID), $destinationGroupID, urlencode($destinationMemberID), $moveMembers);
143                 echo str_replace ($originalValues, $replaceValues, $Translation[
'batch transfer link']);
144             ?>
145         </div>
146
147         <a href=
"pageTransferOwnership.php" class="btn btn-default btn-lg vspacer-lg"><i class="glyphicon glyphicon-chevron-left"></i> <?php echo $Translation['batch transfer']; ?></a>
148
149         <?php
150
151         
// quit
152         include(
"{$currDir}/incFooter.php");
153     }
154 ?>
155
156 <div
class="page-header"><h1><?php echo $Translation['ownership batch transfer']; ?></h1></div>
157
158 <form method=
"get" action="pageTransferOwnership.php" class="form-horizontal">
159
160     <div id=
"step-1" class="panel panel-default">
161         <div
class="panel-heading">
162             <h3
class="panel-title">
163                 <b><?php echo $Translation[
'step 1']; ?></b>
164                 <?php
if($sourceGroupID){ ?>
165                     <span
class="pull-right text-success">
166                         <i
class="glyphicon glyphicon-ok"></i>
167                         <?php echo $Translation[
'source group']; ?>:
168                         <b><?php echo sqlValue(
"select name from membership_groups where groupID='{$sourceGroupID}'"); ?></b>
169                     </span>
170                 <?php } ?>
171             </h3>
172         </div>
173         <div
class="panel-body">
174             <div
class="step-details"><?php echo $Translation['batch transfer wizard']; ?></div>
175             <div
class="form-group">
176                 <label
for="sourceGroupID" class="control-label col-sm-2"><?php echo $Translation['source group']; ?></label>
177                 <div
class="col-sm-6 col-md-4">
178                     <?php echo htmlSQLSelect(
"sourceGroupID", "select distinct g.groupID, g.name from membership_groups g, membership_users u where g.groupID=u.groupID order by g.name", $sourceGroupID); ?>
179                     <?php
if($sourceGroupID){ ?>
180                         <span
class="help-block text-info">
181                             <i
class="glyphicon glyphicon-info-sign"></i>
182                             <?php
183                                 $originalValues = array(
'<MEMBERS>', '<RECORDS>');
184                                 $membersNum = sqlValue(
"select count(1) from membership_users where groupID='$sourceGroupID'");
185                                 $recordsNum = sqlValue(
"select count(1) from membership_userrecords where groupID='$sourceGroupID'");
186                                 $replaceValues = array($membersNum, $recordsNum);
187                                 echo str_replace($originalValues, $replaceValues, $Translation[
'group statistics']);
188                             ?>
189                         </span>
190                     <?php } ?>
191                 </div>
192                 <div
class="col-sm-4 col-md-2">
193                     <button type=
"submit" class="btn btn-block btn-primary">
194                         <i
class="glyphicon glyphicon-ok"></i>
195                         <?php echo ($sourceGroupID ? $Translation[
'update'] : $Translation['next step']); ?>
196                     </button>
197                 </div>
198             </div>
199         </div>
200     </div>
201
202     <?php
if($sourceGroupID){ ?>
203         <div id=
"step-2" class="panel panel-default">
204             <div
class="panel-heading">
205                 <h3
class="panel-title">
206                     <b><?php echo $Translation[
'step 2'] ; ?></b>
207                     <?php
if($sourceMemberID){ ?>
208                         <span
class="pull-right text-success">
209                             <i
class="glyphicon glyphicon-ok"></i>
210                             <?php echo $Translation[
'source member']; ?>:
211                             <b><?php echo $sourceMemberID; ?></b>
212                         </span>
213                     <?php } ?>
214                 </h3>
215             </div>
216             <div
class="panel-body">
217                 <div
class="step-details"><?php echo $Translation['source member message'] ; ?></div>
218                 <div
class="form-group">
219                     <label
for="sourceGroupID" class="control-label col-sm-2"><?php echo $Translation['source member'] ; ?></label>
220                     <div
class="col-sm-6 col-md-4">
221                         <?php
222                             $arrVal[] =
'';
223                             $arrCap[] =
'';
224                             $arrVal[] =
'-1';
225                             $arrCap[] = str_replace (
'<GROUPNAME>', html_attr(sqlValue("select name from membership_groups where groupID='$sourceGroupID'")), $Translation['all group members']);
226                             
if($res = sql("select lcase(memberID), lcase(memberID) from membership_users where groupID='$sourceGroupID' order by memberID", $eo)){
227                                 
while($row = db_fetch_row($res)){
228                                     $arrVal[] = $row[
0];
229                                     $arrCap[] = $row[
1];
230                                 }
231                                 echo htmlSelect(
"sourceMemberID", $arrVal, $arrCap, $sourceMemberID);
232                             }
233                         ?>
234                         <?php
if($sourceMemberID){ ?>
235                             <span
class="help-block text-info">
236                                 <i
class="glyphicon glyphicon-info-sign"></i>
237                                 <?php
238                                     $recordsNum = sqlValue(
"select count(1) from membership_userrecords where ".($sourceMemberID==-1 ? "groupID='$sourceGroupID'" : "memberID='$sourceMemberID'"));
239                                     echo str_replace (
'<RECORDS>', $recordsNum, $Translation['member statistics']);
240                                 ?>
241                             </span>
242                         <?php } ?>
243                     </div>
244                     <div
class="col-sm-4 col-md-2">
245                         <button type=
"submit" class="btn btn-block btn-primary">
246                             <i
class="glyphicon glyphicon-ok"></i>
247                             <?php echo ($sourceMemberID ? $Translation[
'update'] : $Translation['next step']); ?>
248                         </button>
249                     </div>
250                 </div>
251             </div>
252         </div>
253     <?php } ?>
254
255     <?php
if($sourceMemberID){ ?>
256         <div id=
"step-3" class="panel panel-default">
257             <div
class="panel-heading">
258                 <h3
class="panel-title">
259                     <b><?php echo $Translation[
'step 3']; ?></b>
260                     <?php
if($destinationGroupID){ ?>
261                         <span
class="pull-right text-success">
262                             <i
class="glyphicon glyphicon-ok"></i>
263                             <?php echo $Translation[
'destination group']; ?>:
264                             <b><?php echo sqlValue(
"select name from membership_groups where groupID='{$destinationGroupID}'"); ?></b>
265                         </span>
266                     <?php } ?>
267                 </h3>
268             </div>
269             <div
class="panel-body">
270                 <div
class="step-details"><?php echo $Translation['destination group message']; ?></div>
271                 <div
class="form-group">
272                     <label
for="destinationGroupID" class="control-label col-sm-2"><?php echo $Translation['destination group']; ?></label>
273                     <div
class="col-sm-6 col-md-4">
274                         <?php echo htmlSQLSelect(
"destinationGroupID", "select distinct membership_groups.groupID, name from membership_groups, membership_users where membership_groups.groupID=membership_users.groupID order by name", $destinationGroupID); ?>
275                         <span
class="help-block"></span>
276                     </div>
277                     <div
class="col-sm-4 col-md-2">
278                         <button type=
"submit" class="btn btn-block btn-primary">
279                             <i
class="glyphicon glyphicon-ok"></i>
280                             <?php echo ($destinationGroupID ? $Translation[
'update'] : $Translation['next step']); ?>
281                         </button>
282                     </div>
283                 </div>
284             </div>
285         </div>
286     <?php } ?>
287
288     <?php
if($destinationGroupID && $destinationGroupID == $sourceGroupID){ /* source group same as destination */ ?>
289         <div id=
"step-4" class="panel panel-default">
290             <div
class="panel-heading">
291                 <h3
class="panel-title">
292                     <b><?php echo $Translation[
'step 4'] ; ?></b>
293                     <?php
if($destinationMemberID){ ?>
294                         <span
class="pull-right text-success">
295                             <i
class="glyphicon glyphicon-ok"></i>
296                             <?php echo $Translation[
'destination member']; ?>:
297                             <b><?php echo $destinationMemberID; ?></b>
298                         </span>
299                     <?php } ?>
300                 </h3>
301             </div>
302             <div
class="panel-body">
303                 <div
class="step-details"><?php echo $Translation['destination member message'] ; ?></div>
304                 <div
class="form-group">
305                     <label
for="sourceGroupID" class="control-label col-sm-2"><?php echo $Translation['destination member'] ; ?></label>
306                     <div
class="col-sm-6 col-md-4">
307                         <?php
308                             echo htmlSQLSelect(
"destinationMemberID", "select lcase(memberID), lcase(memberID) from membership_users where groupID='$destinationGroupID' and lcase(memberID)!='$sourceMemberID' order by memberID", $destinationMemberID);
309                         ?>
310                     </div>
311                 </div>
312             </div>
313         </div>
314
315     <?php }elseif($destinationGroupID){
/* source group not same as destination */ ?>
316         <div id=
"step-4" class="panel panel-default">
317             <div
class="panel-heading">
318                 <h3
class="panel-title">
319                     <b><?php echo $Translation[
'step 4'] ; ?></b>
320                 </h3>
321             </div>
322             <div
class="panel-body">
323                 <div
class="step-details">
324                     <?php
325                         $anon_group_safe = makeSafe($adminConfig[
'anonymousGroup'], false);
326                         $noMove = ($sourceGroupID == sqlValue(
"select groupID from membership_groups where name='{$anon_group_safe}'"));
327                         $destinationHasMembers = sqlValue(
"select count(1) from membership_users where groupID='{$destinationGroupID}'");
328
329                         
if(!$noMove){
330                             echo $Translation[
'move records'] ;
331                         }
332                     ?>
333                 </div>
334
335                 <?php
if($destinationHasMembers){ ?>
336                     <div
class="form-group">
337                         <label
class="col-xs-12 col-sm-8 col-md-6">
338                             <input type=
"radio" name="moveMembers" id="dontMoveMembers" value="0" <?php echo ($moveMembers ? "" : "checked"); ?>>
339                             <?php
340                                 echo $Translation[
'move data records to member'] . ' ';
341                                 echo htmlSQLSelect(
"destinationMemberID", "select lcase(memberID), lcase(memberID) from membership_users where groupID='$destinationGroupID' order by memberID", $destinationMemberID);
342                             ?>
343                         </label>
344                     </div>
345                 <?php } ?>
346
347                 <?php
if(!$noMove){ ?>
348                     <div
class="form-group">
349                         <label
class="col-md-10">
350                             <input type=
"radio" name="moveMembers" id="moveMembers" value="1" <?php echo ($moveMembers || !$destinationHasMembers ? "checked" : ""); ?>>
351                             <?php echo str_replace(
'<GROUPNAME>', sqlValue("select name from membership_groups where groupID='$destinationGroupID'"), $Translation['move source member to group']); ?>
352                         </label>
353                     </div>
354                 <?php } ?>
355
356             </div>
357         </div>
358     <?php } ?>
359
360     <?php
if($destinationGroupID){ ?>
361         <div
class="row">
362             <div
class="col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3 col-lg-4 col-lg-offset-4">
363                 <button type=
"submit" name="beginTransfer" value="1" class="btn btn-lg btn-success btn-block" onClick="return jsConfirmTransfer();">
364                     <i
class="glyphicon glyphicon-ok"></i>
365                     <?php echo $Translation[
'begin transfer']; ?>
366                 </button>
367             </div>
368         </div>
369     <?php } ?>
370 </form>
371
372 <style>
373     .step-details{ margin: 1em
0; font-size: 1.2em; }
374     form{ margin-bottom: 2em; }
375 </style>
376
377 <script>
378     $j(function(){
379         $j(
'select').addClass('form-control').attr('style', 'width: 100% !important;');
380
381         
/* when a select is changed, automatically apply the change */
382         $j(
'select').change(function(){
383             $j(
this).parent().next().children('.btn').click();
384         })
385     })
386 </script>
387
388 <?php
389     include(
"{$currDir}/incFooter.php");
390 ?>


Gõ tìm kiếm nhanh...